{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "730695ba",
   "metadata": {},
   "source": [
    "## 上周回顾\n",
    "\n",
    "> * 1.list的一般方法/函数的使用及案例，如：\n",
    ">> 1. append() 增加，增加list元素到list的末尾，常用于新建列表\n",
    ">> 2. pop(index)/remove(values) 对比两者优势\n",
    ">> 3. count() 查看某个元素出现次数\n",
    ">> 4. index() 查看某个元素第一次出现的位置\n",
    ">> 5. extend() 两个list合并到一起，也可用[ ]+[ ]来实现\n",
    ">> 6. sort() 排序 默认从小到大排序\n",
    ">> 7. clear() 清空列表\n",
    "\n",
    "> * 2. list的高级用法，如：\n",
    ">> 1. copy() list (可变的数据类型) 复制 不等价于 赋值，可用[:]来实现\n",
    ">> 2. enumerate() 枚举，可同时遍历并获取index和values\n",
    "\n",
    "## 本周练习：\n",
    "\n",
    "### list练习， vowels.py vowels2.py\n",
    "\n",
    "### list实践：\n",
    "\n",
    "### 初始字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d372c98",
   "metadata": {},
   "source": [
    "> * vowels.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "94d6c7d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "# 检查 word中出现的 元音，并打印出来 怎么做？\n",
    "# for letter in word:  # 第一个元素letter 请不要和已有变量重名\n",
    "                     # 第一个元素一般不定义名字，常用item（元素）来命名/简写i来命名\n",
    "                     # 第二个元素 （重要），意味着将遍历的内容\n",
    "                     # 遍历内容一般是 序列数据 str list\n",
    "            \n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b714efd",
   "metadata": {},
   "source": [
    "> * vowels2.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0449c623",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['i', 'a']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用append（） 新建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "    if letter in vowels: # letter在元音字母表中\n",
    "        if letter not in found:  # letter 不在found表中\n",
    "            found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "038631cb",
   "metadata": {},
   "source": [
    "> * list 实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0f5b3e5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账户余额：100\n",
      "编码： 0 ['纸巾', 5]\n",
      "编码： 1 ['糖果', 10]\n",
      "编码： 2 ['奶茶', 15]\n",
      "编码： 3 ['电饭煲', 350]\n"
     ]
    }
   ],
   "source": [
    "# 每个商品的内容是多个值的值，可选用list\n",
    "products = [[\"纸巾\",5],[\"糖果\",10],[\"奶茶\",15],[\"电饭煲\",350]]\n",
    "# 用户购物信息数据存放\n",
    "shopping_list = []\n",
    "# 用户输入余额信息\n",
    "balance = input(\"请输入您的账户余额：\")\n",
    "# 打印商品信息\n",
    "# info = ''' ------------- good list ---------------\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# 商品编号： %s, 商品名称：%s, 商品价格：%s\n",
    "# '''%(0,products[0][0],products[0][1],\n",
    "#      1,products[1][0],products[1][1],\n",
    "#      0,products[2][0],products[2][1],\n",
    "#      0,products[3][0],products[3][1],)\n",
    "# print(info)\n",
    "# list的长度？ len（）\n",
    "\n",
    "# 执行循环\n",
    "\n",
    "while True:\n",
    "    print('------------- good list ---------------')\n",
    "    for i in range(len(products)):\n",
    "        print(\"商品编号： %s, 商品名称：%s, 商品价格：%s元\"%(i,products[i][0],products[i][1]))\n",
    "    # 用户输入商品编号，实现查询\n",
    "    choice = int(input(\"请输入商品编号:\")) # input 输入的内容默认是字符串str，例如输入2，则显示“2”\n",
    "    if choice.isdigit():\n",
    "        # 判断编号是否存在\n",
    "        if choice < len(products):\n",
    "            # 检查用户余额 > 商品价格\n",
    "            if balance > products[choice][1]:\n",
    "                balance = balance - products[choice][1]  # 用户余额发生变化，要扣除\n",
    "                shopping_list.append(products[choice])\n",
    "                pass\n",
    "            else:\n",
    "                print(\"您的余额已不足，请更换其他支付方式\")\n",
    "            pass\n",
    "        else:\n",
    "            print(\"请输入正确的商品编号，您输入的商品不存在\")\n",
    "    elif choice == \"退出\":\n",
    "    \n",
    "    # 打印用户余额和用户的商品列表信息\n",
    "    print(\"用户余额：%s,购物车：%s\"%(balance,shopping_list))\n",
    "    # for i in products:\n",
    "    #     print(\"编码：\",products.index(i),i)\n",
    "    \n",
    "# shoppingcar = input(\"请输入选购商品的编码，加入购物车：\")\n",
    "# shopping_list.append()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ec8eb0d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
